import {config} from '../config/index.js'

export const createStudent = (data)=>{
	 return	new Promise((resolve, reject)=>{
		uni.request({
				url:`/admin/wx/student/create`,
				method:'post',
				data,
				success(resp) {
					resolve(resp.data.data)
				},
				fail(e) {
					reject(new Error('请求失败'));
				}
			})
	})

}

export const selectStudent = (data)=>{
	 return	new Promise((resolve, reject)=>{
		// 构建查询字符串
		const queryString = data ? Object.keys(data)
			.filter(key => data[key] !== null && data[key] !== undefined)
			.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`)
			.join('&') : '';
		const url = queryString ? `/admin/wx/student/listStudent?${queryString}` : `/admin/wx/student/listStudent`;

		uni.request({
				url,
				method:'get',
				success(resp) {
					resolve(resp.data.data)
				},
				fail(e) {
					reject(new Error('请求失败'));
				}
			})
	})

}

export const updateStudent = (data)=>{
	 return	new Promise((resolve, reject)=>{
		uni.request({
				url:`/admin/wx/student/update`,
				method:'post',
				data,
				success(resp) {
					resolve(resp.data.data)
				},
				fail(e) {
					reject(new Error('请求失败'));
				}
			})
	})

}

export const bindStudent = (id)=>{
	 return	new Promise((resolve, reject)=>{
		uni.request({
				url:`/admin/wx/student/bindList/${id}`,
				method:'get',
				success(resp) {
					resolve(resp.data.data)
				},
				fail(e) {
					reject(new Error('请求失败'));
				}
			})
	})

}

export const removeBindStudent = (id)=>{
	 return	new Promise((resolve, reject)=>{
		uni.request({
				url:`/admin/wx/student/removeBind/${id}`,
				method:'post',
				success(resp) {
					resolve(resp.data.data)
				},
				fail(e) {
					reject(new Error('请求失败'));
				}
			})
	})

}

export const detailStudent = (id)=>{
	 return	new Promise((resolve, reject)=>{
		uni.request({
				url:`/admin/wx/student/detail/${id}`,
				method:'get',
				success(resp) {
					resolve(resp.data.data)
				},
				fail(e) {
					reject(new Error('请求失败'));
				}
			})
	})

}

export const getSchoolList = (params)=>{
	 return	new Promise((resolve, reject)=>{
		// 构建查询字符串
		const queryString = params ? Object.keys(params)
			.filter(key => params[key] !== null && params[key] !== undefined)
			.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
			.join('&') : '';
		const url = queryString ? `/admin/wx/student/listSchool?${queryString}` : `/admin/wx/student/listSchool`;

		uni.request({
				url,
				method:'get',
				success(resp) {
					resolve(resp.data.data)
				},
				fail(e) {
					reject(new Error('请求失败'));
				}
			})
	})

}